package com.its.web;

import com.github.pagehelper.PageInfo;
import com.its.pojo.BusInsurancePolicy;
import com.its.service.BusInsurancePolicyService;
import com.its.util.HttpStatusEnum;
import com.its.util.Result;
import com.its.web.param.BusInsurancePolicyControllerListParam;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 朱厚强
 */
@RestController
@RequestMapping("/BusInsurancePolicyController")
@Api(tags = "保单-api" )
public class BusInsurancePolicyController {
    @Autowired
    private BusInsurancePolicyService service;
    @PostMapping("/pagingList")
    public Result pagingList(@RequestBody BusInsurancePolicyControllerListParam busInsurancePolicyControllerListParam) {
        PageInfo<BusInsurancePolicy> pageInfo = service.selectList(busInsurancePolicyControllerListParam);
        if (pageInfo.getSize()>0){
            return Result.ok().code(HttpStatusEnum.SUCCESS.getCode()).data(pageInfo).message("保单信息查询成功");
        }else {
            return Result.ok().code(HttpStatusEnum.ERROR.getCode()).data(pageInfo).message("保单信息查询失败");
        }
    }

    /**
     * 根据被保人姓名以及被保人身份证号获取报案信息
     * @return
     */
    @GetMapping("/getPolicy")
    public Result getPolicy(@RequestParam String name,@RequestParam String cardID ){
        BusInsurancePolicy busInsurancePolicy = service.getByInsuredNameAndCardID( name, cardID);
        if (busInsurancePolicy != null){
            return Result.ok().data(busInsurancePolicy).code(HttpStatusEnum.SUCCESS.getCode()).message("返回保单信息");
        }else {
            return Result.error().data(busInsurancePolicy).code(HttpStatusEnum.SUCCESS.getCode()).message("所查询保单信息为空");
        }
    }

    /**
     * 根据身份证号来查询信息
     */
    @GetMapping("/getPlicylist")
    public Result getPlicylist(@RequestParam(value = "insuredId",required = false,defaultValue = "") String  insuredId){
        System.out.println("!!!"+insuredId);
        // 为空校验
        if (!"".equals(insuredId)){
            List<BusInsurancePolicy> byinsuredId = service.getByinsuredId(insuredId);
            if(byinsuredId != null){
                return  Result.ok().code(HttpStatusEnum.SUCCESS.getCode()).data(byinsuredId).message("数据查询成功");
            }else {
                return  Result.error().code(HttpStatusEnum.ERROR.getCode()).data(byinsuredId).message("数据查询失败");
            }
        }else {
            return  Result.error().code(HttpStatusEnum.ERROR.getCode()).message("身份证信息为空");
        }

    }
}
